package com.zhoug.common3.view.dialog;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;

import com.zhoug.common3.R;
import com.zhoug.common3.utils.LogUtils;

import androidx.annotation.AttrRes;
import androidx.annotation.StyleRes;

/**
 * @Author 35574
 * @Date 2020/7/22
 * @Description
 */
 class DialogAttributeParser {
    private static final String TAG = ">>>DialogAttributeParser";
    private static  boolean debug = false;

    public static void setDebug(boolean debug) {
        DialogAttributeParser.debug = debug;
    }

    /**
     * {@link R.styleable#ZBaseDialog}中的属性,可以调用此方法解析
     *
     * @param context      Context
     * @param defStyleAttr 全局默认样式的AttrRes,需要在Theme中指定
     * @param defStyleRes  默认的Style
     */
    public static void parseZBaseDialogAttrs(ZBaseDialog dialog, Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        if (dialog == null) return;
        TypedArray a = context.obtainStyledAttributes(null, R.styleable.ZBaseDialog, defStyleAttr, defStyleRes);
        int corners = a.getDimensionPixelOffset(R.styleable.ZBaseDialog_zg_corners, 0);
        boolean fullWidth = a.getBoolean(R.styleable.ZBaseDialog_zg_fullWidth, false);
        int titleColor = a.getColor(R.styleable.ZBaseDialog_zg_titleColor,0);
        float titleSize = a.getDimension(R.styleable.ZBaseDialog_zg_titleSize, 0);
        int messageColor = a.getColor(R.styleable.ZBaseDialog_zg_messageColor, 0);
        float messageSize = a.getDimension(R.styleable.ZBaseDialog_zg_messageSize, 0);
        int maxHeight = a.getDimensionPixelOffset(R.styleable.ZBaseDialog_zg_maxHeight, 0);
        a.recycle();
        if (debug) {
            LogUtils.d(TAG, "ZBaseDialog:corners=" + corners);
            LogUtils.d(TAG, "ZBaseDialog:fullWidth=" + fullWidth);
            LogUtils.d(TAG, "ZBaseDialog:titleColor=" + Integer.toHexString(titleColor));
            LogUtils.d(TAG, "ZBaseDialog:titleSize=" + titleSize);
            LogUtils.d(TAG, "ZBaseDialog:messageColor=" + Integer.toHexString(messageColor));
            LogUtils.d(TAG, "ZBaseDialog:messageSize=" + messageSize);
            LogUtils.d(TAG, "ZBaseDialog:maxHeight=" + maxHeight);
        }
            dialog.setCorners(corners);
            dialog.setFullWidth(fullWidth);
            dialog.setTitleColor(titleColor);
            dialog.setTitleSize(titleSize);
            dialog.setMessageColor(messageColor);
            dialog.setMessageSize(messageSize);
            dialog.setMaxHeight(maxHeight);

    }

    /**
     * {@link R.styleable#ZAbsListDialog}中的属性,可以调用此方法解析
     *
     * @param context      Context
     * @param defStyleAttr 全局默认样式的AttrRes,需要在Theme中指定
     * @param defStyleRes  默认的Style
     */
    public static void parseZMUIAbsListDialogAttrs(ZAbsListDialog dialog, Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        if (dialog == null) return;
        TypedArray a = context.obtainStyledAttributes(null, R.styleable.ZAbsListDialog, defStyleAttr, defStyleRes);
        float textSize = a.getDimension(R.styleable.ZAbsListDialog_zg_textSize, 0);
        int textColor = a.getColor(R.styleable.ZAbsListDialog_zg_textColor, 0);
        int dividerHeight = a.getDimensionPixelOffset(R.styleable.ZAbsListDialog_zg_dividerHeight, 1);
        int dividerColor = a.getColor(R.styleable.ZAbsListDialog_zg_dividerColor, Color.parseColor("#dddddd"));
        boolean showDivider = a.getBoolean(R.styleable.ZAbsListDialog_zg_showDivider, true);
        a.recycle();
        if (debug) {
            LogUtils.d(TAG, "ZMUIAbsListDialog:textSize=" + textSize);
            LogUtils.d(TAG, "ZMUIAbsListDialog:textColor=" + Integer.toHexString(textColor));
            LogUtils.d(TAG, "ZMUIAbsListDialog:dividerHeight=" + dividerHeight);
            LogUtils.d(TAG, "ZMUIAbsListDialog:dividerColor=" + Integer.toHexString(dividerColor));
            LogUtils.d(TAG, "ZMUIAbsListDialog:showDivider=" +showDivider);
        }
            dialog.setTextSize(textSize);
            dialog.setTextColor(textColor);
            dialog.setDividerColor(dividerColor);
            dialog.setDividerHeight(dividerHeight);
            dialog.setShowDivider(showDivider);

    }

}
